﻿namespace Cellfish.Toolbox.Facts.Streams
{
    using System.IO;

    using Cellfish.Toolbox.Streams;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class CountingStreamFacts
    {
        [TestMethod]
        public void Given_CountingStream_When_reading_Then_bytes_read_are_counted()
        {
            var ms = new MemoryStream(new byte[42]);
            var cs = new CountingStream(ms);
            cs.Position = 10;
            cs.Read(new byte[50], 0, 50);
            Assert.AreEqual(32, cs.BytesRead);
        }

        [TestMethod]
        public void Given_CountingStream_When_writing_Then_bytes_written_are_counted()
        {
            var ms = new MemoryStream(new byte[42]);
            var cs = new CountingStream(ms);
            cs.Write(new byte[5], 0, 5);
            Assert.AreEqual(5, cs.BytesWritten);
        }
    }
}
